<meta title="优惠券搜索" width="1000px" args="multi:true"/>
<div class="p">
    <div class="m-b clearfix">
        <form class="form-inline pull-left" id="form">
            <select name="searchType" class="form-control input-sm" id="searchType" s-change="$searchTypeParam.refresh()">
                <option value="1">淘宝选品库</option>
                <option value="0">搜索</option>
            </select>
            <div style="display: inline-block" s="tpl" id="searchTypeParam" s-data="$searchType.node.val()">
                {%if(this == '0') {%}
                <input autocomplete="off" type="text" class="form-control input-sm" placeholder="输入关键字" style="width:400px;" name="keywords" />
                <select class="form-control input-sm" s="select" s-build="S.get('/api/enum/valuesMap/core.enums.SearchFrom')"
                        name="searchFrom">
                </select>
                {%} else {%}
                <select class="form-control input-sm" s="select"
                        s-valid-error="require()"
                        s-build="S.get('/api/tbk-api/favorites')"
                        s-select="{title: titleFn, value: valFn}"
                        name="taobaoSelectionId">
                </select>
                {%}%}
            </div>
            <input autocomplete="off" type="hidden" name="page" id="page" value="1"/>
            <button type="button" class="btn btn-default btn-sm" s-click="$page.node.val(1); $commissionItemsGrid.refresh()">查询</button>
        </form>
    </div>
    <div id="commissionItemsGrid"
         s='datac,nda,check'
         s-check="{multiple: multi}"
         s-data-switch="'off-on'"
         s-data="S.get('/api/commission-item/search', $form.node.serialize())"

         style="height: 500px; display: flex; flex-direction: column">
        <div style="display: flex; flex: 1;  overflow-y: auto;">
            <table  class="table table-striped table-bordered table-hover table-middle">
                <tr>
                    <th>
                        <label class="s-checkbox">
                            <input autocomplete="off" type="checkbox" s-check-role="checkall-h"/>
                            <span class="s-checkbox-indicator"></span>
                        </label>
                    </th>
                    <th>图片</th>
                    <th style="max-width: 300px;">名称</th>
                    <th>价格</th>
                    <th>卖家</th>
                    <th>原价</th>
                    <th>券值</th>
                    <th>推荐</th>
                    <th>佣金</th>
                    <th>平台</th>
                    <th class="text-right">操作</th>
                </tr>
                <tbody s="loop" s-data-filter="'results'">
                <tr s-loop-role="empty">
                    <td colspan="11">暂无数据</td>
                </tr>
                <tr s-loop-role="row" s-check-role="i" s="datac" class="commissionItem">
                    <td>
                        <label class="s-checkbox">
                            <input autocomplete="off" type="checkbox" s-check-role="h" />
                            <span class="s-checkbox-indicator"></span>
                        </label>
                    </td>
                    <td s="tpl">
                        <img src="{%=this.picUrl%}" style="max-width: 80px; max-height: 80px;" />
                    </td>
                    <td s="tpl">
                        <a href="{%=this.sourceItemUrl%}"
                           target="_blank" external>{%=this.title%}</a>
                    </td>
                    <td name="price"></td>
                    <td name="shopTitle"></td>
                    <td name="originPrice"></td>
                    <td name="couponValue"></td>
                    <td s="tpl">
                        {%if(this.recommend){%}
                        <label class="label label-success">推荐</label>
                        {%}else{%}
                        <label class="label label-info">普通</label>
                        {%}%}
                    </td>
                    <td s="tpl">
                        {%if(this.highCommission){%}
                        <label class="label label-warning">{%=this.commissionRate%}%</label>
                        {%}else{%}
                        <label class="label label-info">{%=this.commissionRate%}%</label>
                        {%}%}
                    </td>
                    <td name="ecomPlatTitle"></td>
                    <td class="text-right" s="tpl">
                        <a href="javascript:;" class="btn btn-default btn-xs" s-click=" (this)">选择</a>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
        <div style="display: flex;">
            <ul s="pagination"
                s-pagination="{action:function(){$page.node.val(this); $commissionItemsGrid.refresh()}}"
                class="pagination pagination-sm">
            </ul>
        </div>
    </div>
</div>
<script type="text/javascript">

    function select($this) {
        S.close([$this.parent().data()])
    }

    function titleFn(obj) {
        return obj.favoritesTitle + (obj.type === 2 ? " - 高佣" : '');
    }

    function valFn(obj) {
        return obj.favoritesId
    }

    S.meta.btns = [
        {
            name: "选择",
            style: "btn btn-primary",
            click: function() {
                var datas = $commissionItemsGrid.getCheckedData();
                if (datas.length) {
                    S.close(datas);
                } else {
                    S.toast("您还没有选择商品！", "warning");
                }
            }
        },
        {
            name: "关闭",
            style: "btn btn-default",
            click: function() {
                S.close();
            }
        }
    ]

</script>